package com.ada.spark.datasource

import org.apache.spark.SparkConf
import org.apache.spark.sql.{Dataset, Encoders, SparkSession}
import org.apache.spark.sql.catalyst.expressions.Encode

object JsonTest {

    def main(args: Array[String]): Unit = {
        //创建配置对象
        val conf: SparkConf = new SparkConf().setAppName("JsonTest").setMaster("local[*]")

        //创建SparkSql的环境对象
        val spark: SparkSession = SparkSession.builder().config(conf).getOrCreate();

        //导入隐式转换函数
        import spark.implicits._

        val peopleDF = spark.read.json("format/people.json")

        peopleDF.printSchema()

        peopleDF.createOrReplaceTempView("people")

        val teenagerNamesDF = spark.sql("SELECT name FROM people WHERE age BETWEEN 13 AND 19")

        teenagerNamesDF.show()

    }
}
